// utils/wechat.js
export function loadWeChatSDK() {
  return new Promise((resolve, reject) => {
    if (typeof wx !== 'undefined') {
      resolve(wx);
      return;
    }

    const script = document.createElement('script');
    script.src = 'https://res.wx.qq.com/open/js/jweixin-1.6.0.js';
    script.onload = () => {
      if (typeof wx !== 'undefined') {
        resolve(wx);
      } else {
        reject(new Error('微信 JS-SDK 加载失败'));
      }
    };
    script.onerror = () => reject(new Error('微信 JS-SDK 加载出错'));
    document.head.appendChild(script);
  });
}
